package com.atguigu.service.impl;

import com.atguigu.dao.RoleDao;
import com.atguigu.domain.Permission;
import com.atguigu.domain.Role;
import com.atguigu.service.ProductService;
import com.atguigu.service.RoleService;
import com.atguigu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;


    @Override
    public List<Role> findAll() {
        return roleDao.findAl();
    }

    @Override
    public void save(Role role) {
        roleDao.save(role);
    }

    @Override
    public Role findById(String id) {
        return roleDao.findById(id);
    }

    @Override
    public void deleteRole(String roleId) {
        roleDao.deleteRole(roleId);//删除角色
        System.out.println("删除成功1");
        roleDao.deleteUsersRole(roleId);//删除Users_Role
        System.out.println("删除成功2");
        roleDao.deletepermissionRole(roleId);//删除permission_Role
        System.out.println("删除成功3");
    }

    @Override
    public List<Permission> findOtherPermission(String id) {
        return roleDao.findOtherPermission(id);
    }

    @Override
    public void addPermissionToRole(String roleId, String[] permissionIds) {
        for (String permissionId:permissionIds) {
            roleDao.addPermissionToRole(roleId,permissionId);
        }
    }

}
